import java.util.Arrays;
import java.util.Comparator;


public class Sorting
{
  /**
   * @param args
   */
  public static void main(String[] args)
  {
    Integer[] originalItems = {3, 8, 4, 5, 4, 7};
    Integer[] items = null;
    
    items = originalItems.clone();
    System.out.println("Items: " + Arrays.toString(items));
    System.out.println("Sorting (asc)...");
    testComparator(items, asc);
    System.out.println("Sorted items: " + Arrays.toString(items));
    System.out.println();
    
    items = originalItems.clone();
    System.out.println("Items: " + Arrays.toString(items));
    System.out.println("Sorting (desc)...");
    testComparator(items, desc);
    System.out.println("Sorted items: " + Arrays.toString(items));
    System.out.println();
  }
  
  
  public static void testComparator(Integer[] items, Comparator<Integer> c)
  {
    Arrays.sort(items, c);
  }
  
  
  //-------------------
  // Comparators...
  //-------------------
  
  static Comparator<Integer> asc = new Comparator<Integer>(){
    public int compare(Integer o1, Integer o2)
    {
      if (o1 > o2)
        return 1;
      else if (o1 == o2)
        return 0;
      return -1;
    }
  };
  static Comparator<Integer> desc = new Comparator<Integer>(){
    public int compare(Integer o1, Integer o2)
    {
      if (o1 > o2)
        return -1;
      else if (o1 == o2)
        return 0;
      return 1;
    }
  };
}
